﻿using UnityEngine;
using System.Collections;

public class PatternFather : MonoBehaviour 
{
    private float childSpeed;
    private Transform[] childs;
    public Transform last;

    void Start()
    {
        childs = gameObject.GetComponentsInChildren<Transform>();
    }
    
	void Update() 
    {
        childs = gameObject.GetComponentsInChildren<Transform>();

        if(childs.Length == 1)
        {
            Destroy(gameObject);
        }
	}

    public void setSpeed(float speed)
    {
        childs = gameObject.GetComponentsInChildren<Transform>();

        foreach (Transform t in childs)
        {
            if (t.GetComponent<Building>())
            {
                t.GetComponent<Building>().speed += speed;
            }

            if (t.tag == "LastBuilding")
            {
                last = t;
            }
            
            if (t.GetComponent<Bird>())
            {
                t.GetComponent<Bird>().speed += speed;
            }
        }
    }
}
